package com.webank.webase.chain.mgr.repository.mapper;

import com.webank.webase.chain.mgr.repository.bean.TbContractPath;
import com.webank.webase.chain.mgr.repository.bean.TbContractPathExample;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface TbContractPathMapper {

    @Delete({
        "delete from tb_contract_path",
        "where chain_id = #{chainId,jdbcType=INTEGER} and group_id = #{groupId,jdbcType=INTEGER}",
        "and contract_path = #{contractPath}"
    })
    Integer removeByPathName(@Param("chainId") Integer chainId, @Param("groupId") Integer groupId,
        @Param("contractPath") String contractPath);

    @Select({
        "select",
        TbContractPathSqlProvider.ALL_COLUMN_FIELDS,
        "from tb_contract_path",
        "where chain_id = #{chainId,jdbcType=INTEGER} and group_id = #{groupId,jdbcType=INTEGER}",
        "and contract_path = #{contractPath}"
    })
    TbContractPath findOne(@Param("chainId") Integer chainId, @Param("groupId") Integer groupId,
        @Param("contractPath") String contractPath);

    @Select({
        "select",
        TbContractPathSqlProvider.ALL_COLUMN_FIELDS,
        "from tb_contract_path",
        "where chain_id = #{chainId,jdbcType=INTEGER} and group_id = #{groupId,jdbcType=INTEGER}"
    })
    List<TbContractPath> listContractPath(@Param("chainId") Integer chainId,
        @Param("groupId") Integer groupId);

    @Delete({ "delete from tb_contract_path where chain_id = #{chainId}" })
    int removeByChainId(@Param("chainId") Integer chainId);

    @Delete({
        "delete from tb_contract_path",
        "where chain_id = #{chainId,jdbcType=INTEGER} and group_id = #{groupId,jdbcType=INTEGER}"
    })
    int removeByGroupId(@Param("chainId") Integer chainId, @Param("groupId") Integer groupId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @SelectProvider(type= TbContractPathSqlProvider.class, method="countByExample")
    long countByExample(TbContractPathExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @DeleteProvider(type= TbContractPathSqlProvider.class, method="deleteByExample")
    int deleteByExample(TbContractPathExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @Delete({
        "delete from tb_contract_path",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @Insert({
        "insert into tb_contract_path (contract_path, chain_id, ",
        "group_id, create_time, ",
        "modify_time)",
        "values (#{contractPath,jdbcType=VARCHAR}, #{chainId,jdbcType=INTEGER}, ",
        "#{groupId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(TbContractPath record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @InsertProvider(type= TbContractPathSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insertSelective(TbContractPath record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @SelectProvider(type= TbContractPathSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="contract_path", property="contractPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="chain_id", property="chainId", jdbcType=JdbcType.INTEGER),
        @Result(column="group_id", property="groupId", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    List<TbContractPath> selectByExample(TbContractPathExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @Select({
        "select",
        "id, contract_path, chain_id, group_id, create_time, modify_time",
        "from tb_contract_path",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="contract_path", property="contractPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="chain_id", property="chainId", jdbcType=JdbcType.INTEGER),
        @Result(column="group_id", property="groupId", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    TbContractPath selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @UpdateProvider(type= TbContractPathSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbContractPath record,
        @Param("example") TbContractPathExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @UpdateProvider(type= TbContractPathSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") TbContractPath record,
        @Param("example") TbContractPathExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @UpdateProvider(type= TbContractPathSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbContractPath record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @Update({
        "update tb_contract_path",
        "set contract_path = #{contractPath,jdbcType=VARCHAR},",
          "chain_id = #{chainId,jdbcType=INTEGER},",
          "group_id = #{groupId,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(TbContractPath record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true,keyProperty="id",keyColumn = "id")
    @Insert({
    "<script>",
        "insert into tb_contract_path (contract_path, ",
        "chain_id, group_id, ",
        "create_time, modify_time)",
        "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.contractPath,jdbcType=VARCHAR}, ",
        "#{detail.chainId,jdbcType=INTEGER}, #{detail.groupId,jdbcType=INTEGER}, ",
        "#{detail.createTime,jdbcType=TIMESTAMP}, #{detail.modifyTime,jdbcType=TIMESTAMP})</foreach></script>"
    })
    int batchInsert(List<TbContractPath> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract_path
     *
     * @mbg.generated
     */
    @SelectProvider(type= TbContractPathSqlProvider.class, method="getOneByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="contract_path", property="contractPath", jdbcType=JdbcType.VARCHAR),
        @Result(column="chain_id", property="chainId", jdbcType=JdbcType.INTEGER),
        @Result(column="group_id", property="groupId", jdbcType=JdbcType.INTEGER),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Optional<TbContractPath> getOneByExample(TbContractPathExample example);
}